import 'package:appflutterhomeschool/api/api_service.dart';
import 'package:appflutterhomeschool/api/dio_utils.dart';
import 'package:appflutterhomeschool/view_model/my_app_view_model.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';

class KnowledgeStatisticsViewModel extends ChangeNotifier {
  BuildContext me;
  List nodesList;

  KnowledgeStatisticsViewModel(this.me);

  MyAppViewModel myAppViewModel;

  initView() {
    myAppViewModel = Provider.of(me);

    DioUtils.getInstance().post(
        myAppViewModel.identity
            ? ApiService.getClsNodes
            : ApiService.getStuNodes,
        myAppViewModel.identity
            ? {
                "cls_mapping_id":
                    myAppViewModel.studentInformationModel.classMappingId,
              }
            : {
                "student_id": myAppViewModel.studentInformationModel.subjectId,
                "cls_id": myAppViewModel.studentInformationModel.classId,
              }, (successCallBack) {
      if (successCallBack == null || successCallBack["data"] == null) {
        return;
      }
      nodesList = [];

      if (myAppViewModel.identity) {
        nodesList = successCallBack["data"]["nodes"];

      } else {
        List nodesMap = successCallBack["data"]["nodes"];
        if (nodesMap == null) {
          return;
        }
        nodesMap.forEach((element) {
          nodesList.add(element);
        });
      }
      notifyListeners();
    }, (errorCallBack) {});
  }
}
